<?php

namespace App\Http\Service\Goods;

use App\Facade\UserFuncFacade;
use App\Func\User\UserFunc;
use App\Models\Goods\GoodsConfigModel;

class ManageGoodsConfigService
{
    public function setConfig($data){
        // 完全替换配置文件
        $comId = (new UserFunc())->getCurrentComId();
        $data['com_id'] = $comId;
        $configModel = new GoodsConfigModel();
        $isExists = $configModel->where('com_id',$comId)->first();
        if(!$isExists){
            $data['created_at'] = date("Y-m-d H:i:s");
            $configModel->insertGetId($data);
        }else{
            $configModel->where('com_id',$comId)->update($data);
        }
        s_c_return(null,trans('message.created_ok',[
            'name' => trans('key.goods_config')
        ]));
    }

    public function getConfig(){
        $comId = (new UserFunc())->getCurrentComId();
        $configModel = new GoodsConfigModel();
        $res = $configModel->where('com_id',$comId)->first();
        s_c_return($res,trans('message.get_detail_ok',[
            'name' => trans('key.goods_config')
        ]));
    }
}
